/**
 * 校园卡信息表
 * 
 *
 *<pre> 
 * 开发公司：苏州东大金点信息技术有限公司
 * 开发人员：唐红锋
 * 邮箱地址：55872655@qq.com
 * 创建时间：2019-09-28 15:21:59
 *</pre>
 */
$(function() {
	campusCard  = new CampusCard();
	campusCard.init();
	
	formUrl = campusCard.formUrl;
});

(function() {
	//定义常量
	var 	_consts = {
			GRID : "#campusCardGrid",// 列表对象
			PAGER : "#campusCardPager",// 列表分页
			FORM : '#campusCardForm',// 表单form
			FORMGET : '#campusCardFormGet'// 表单form
			
	};
	/**
	 * 校园卡信息表 对象
	 * @returns {CampusCard}
	 */
	CampusCard = function() {
		//定义属性
	};

	/**
	 * 方法
	 */
	CampusCard.prototype = {
		consts:	_consts,
		/**
		 * 初始化
		 */
		init : function() {
			if (this.hasInit) // 是否已初始化
				return false;
			this.hasInit = true;
			if ($(this.consts.GRID).length > 0){//列表
				this._initGridList();
				
			}
			if ($(this.consts.FORM).length > 0){//表单
				this._initForm();
				this._initData();
				this._initOffice('e');
			}
			if ($(this.consts.FORMGET).length > 0){// 明细页面office控件初始化
				this._initOffice('r');
			}
		},
		_initOffice : function(_rights){
		},

		/**
		 * 初始列表
		 */
		_initGridList : function() {
			var me = this;
			$(this.consts.GRID).GridList(
					{
						url :  __ctx+'/rdp/user/campusCard/listJson.htm',
						pager :this.consts.PAGER,
						colNames: ['ID','卡号','卡类型0-学生，1-教师，2-临时卡','服务商编码','账户','登录密码','姓名','电话','状态（0-冻结，1-开启,2-解绑,3-挂失）','冻结原因','微信unionid','公众号openid','小程序openid','微信昵称','支付宝id','支付宝昵称','卡片余额','校园卡有效期','支付密码','CREATETIME','CREATEUSER','UPDATETIME','UPDATEUSER','扩展字段1','扩展字段2','扩展字段3','物理卡号','卡流水号','用户默认支付方式（1SIOS/2计次/3劵支付4/聚合支付/8钱包/0未知）','钱包一','钱包二','钱包三','钱包四','钱包五','是否管理员（1普通用户/2管理员/3高校运维人员）','CERTTYPE','CERTNUM','WHITELISTVERSION','EXTENDACCOUNT','ORGCODE','PID','SEX','SCHOOLYEAR','PIDTITLE','管理'],
				        colModel: [{
				                 	   name:'id',
				                	   index: 'ID'

										
				                	 	,hidden:true,key:true
				                	 	}, {
				                 	   name:'cardnum',
				                	   index: 'CARDNUM'

										
				                	 					                	 	}, {
				                 	   name:'cardtype',
				                	   index: 'CARDTYPE'

										
				                	 					                	 	}, {
				                 	   name:'servicecode',
				                	   index: 'SERVICECODE'

										
				                	 					                	 	}, {
				                 	   name:'usernum',
				                	   index: 'USERNUM'

										
				                	 					                	 	}, {
				                 	   name:'pwd',
				                	   index: 'PWD'

										
				                	 					                	 	}, {
				                 	   name:'username',
				                	   index: 'USERNAME'

										
				                	 					                	 	}, {
				                 	   name:'phone',
				                	   index: 'PHONE'

										
				                	 					                	 	}, {
				                 	   name:'status',
				                	   index: 'STATUS'

										
				                	 					                	 	}, {
				                 	   name:'closereason',
				                	   index: 'CLOSEREASON'

										
				                	 					                	 	}, {
				                 	   name:'wxunionid',
				                	   index: 'WXUNIONID'

										
				                	 					                	 	}, {
				                 	   name:'gzhopenid',
				                	   index: 'GZHOPENID'

										
				                	 					                	 	}, {
				                 	   name:'xcxopenid',
				                	   index: 'XCXOPENID'

										
				                	 					                	 	}, {
				                 	   name:'wxnickname',
				                	   index: 'WXNICKNAME'

										
				                	 					                	 	}, {
				                 	   name:'alipayid',
				                	   index: 'ALIPAYID'

										
				                	 					                	 	}, {
				                 	   name:'alipaynickname',
				                	   index: 'ALIPAYNICKNAME'

										
				                	 					                	 	}, {
				                 	   name:'balance',
				                	   index: 'BALANCE'

										
				                	 					                	 	}, {
				                 	   name:'cardvaliditytime',
				                	   index: 'CARDVALIDITYTIME'

										
				                	 					                	 	}, {
				                 	   name:'paypassword',
				                	   index: 'PAYPASSWORD'

										
				                	 					                	 	}, {
				                 	   name:'createtime',
				                	   index: 'CREATETIME'
				                	 	,formatter: 'timestamp'
										
				                	 					                	 	}, {
				                 	   name:'createuser',
				                	   index: 'CREATEUSER'

										
				                	 					                	 	}, {
				                 	   name:'updatetime',
				                	   index: 'UPDATETIME'
				                	 	,formatter: 'timestamp'
										
				                	 					                	 	}, {
				                 	   name:'updateuser',
				                	   index: 'UPDATEUSER'

										
				                	 					                	 	}, {
				                 	   name:'ext1',
				                	   index: 'EXT1'

										
				                	 					                	 	}, {
				                 	   name:'ext2',
				                	   index: 'EXT2'

										
				                	 					                	 	}, {
				                 	   name:'ext3',
				                	   index: 'EXT3'

										
				                	 					                	 	}, {
				                 	   name:'carduid',
				                	   index: 'CARDUID'

										
				                	 					                	 	}, {
				                 	   name:'cardsn',
				                	   index: 'CARDSN'

										
				                	 					                	 	}, {
				                 	   name:'userpaytype',
				                	   index: 'USERPAYTYPE'

										
				                	 					                	 	}, {
				                 	   name:'wallet1',
				                	   index: 'WALLET1'

										
				                	 					                	 	}, {
				                 	   name:'wallet2',
				                	   index: 'WALLET2'

										
				                	 					                	 	}, {
				                 	   name:'wallet3',
				                	   index: 'WALLET3'

										
				                	 					                	 	}, {
				                 	   name:'wallet4',
				                	   index: 'WALLET4'

										
				                	 					                	 	}, {
				                 	   name:'wallet5',
				                	   index: 'WALLET5'

										
				                	 					                	 	}, {
				                 	   name:'isadmin',
				                	   index: 'ISADMIN'

										
				                	 					                	 	}, {
				                 	   name:'certtype',
				                	   index: 'CERTTYPE'

										
				                	 					                	 	}, {
				                 	   name:'certnum',
				                	   index: 'CERTNUM'

										
				                	 					                	 	}, {
				                 	   name:'whitelistversion',
				                	   index: 'WHITELISTVERSION'

										
				                	 					                	 	}, {
				                 	   name:'extendaccount',
				                	   index: 'EXTENDACCOUNT'

										
				                	 					                	 	}, {
				                 	   name:'orgcode',
				                	   index: 'ORGCODE'

										
				                	 					                	 	}, {
				                 	   name:'pid',
				                	   index: 'PID'

										
				                	 					                	 	}, {
				                 	   name:'sex',
				                	   index: 'SEX'

										
				                	 					                	 	}, {
				                 	   name:'schoolyear',
				                	   index: 'SCHOOLYEAR'
				                	 	,formatter: 'timestamp'
										
				                	 					                	 	}, {
				                 	   name:'pidtitle',
				                	   index: 'PIDTITLE'

										
				                	 					                	 	},  {
									name : '__manage',
									width : 30,
									sortable:false,
									classes:'rowOps',
									formatter : 'manage',
									formatoptions :[{
										label:'编辑',
										classes:'btn btn-primary fa fa-edit',
										action:__ctx+'/rdp/user/campusCard/edit.htm?id={id}'
									},{
										label:'删除',
										classes:'btn btn-primary fa fa-remove',
										action:__ctx+'/rdp/user/campusCard/remove.htm?id={id}'
									},{
										label:'明细',
										classes:'btn btn-primary fa fa-detail',
										action: __ctx+'/rdp/user/campusCard/get.htm?id={id}'
									}]
								} ]
	
					});
		},
		
		/**
		 * 初始化表单
		 */
		_initForm : function() {
			var me = this, form = $(this.consts.FORM), frm = form.form();
			me.formUrl = new com.lc.form.FormData(form);
			// 触发表单验证
			frm.valid();
			me.formUrl.initSub('/rdp/user');
			// 处理表单保存
			$(document).on('click', 'a.fa-save', function() {
				var $el = $(this);
				$el.button('loading');
				// office提交
        		OfficePlugin.submit();
				me.formUrl.submit(me._showResponse, $el);
			});
		},
		/**
		 * 初始化数据
		 */
		_initData : function(){
			if(!$.isEmpty(frameElement) 
				&& !$.isEmpty(frameElement.dialog) 
				&& !$.isEmpty(frameElement.dialog.params)
				&& !$.isEmpty(frameElement.dialog.params.data)){
				var data = frameElement.dialog.params.data;
				this.formUrl.setData("[name^='m:']", data);
				AttachementControl.initDataTo($("div[name='div_attachment_container']")); //附件初始化
			}else{
				$("[name^='m:']", $(_consts.FORM)).each(function(){
					var data = $(this);
	        		// 单选框特殊处理 
	            	if(data.is('input') && "radio" == data.attr("type")){
			        		var defaultVal = data.attr("defaultVal");
			        		var defaultValue = data.attr("defaultValue");
		            		if(defaultValue=="true"&&defaultVal=="true"){
		            			data.prop("checked", "checked");
		            		}
		        	}
		        });
			}
			
			this.formUrl.validate();
		},
		/**
		 * 表单成功返回信息
		 * 
		 * @param responseText
		 */
		_showResponse : function(responseText) {
			var msg = new com.lc.form.ResultMessage(responseText);
			if (msg.isSuccess()) {
				DialogUtil.confirm(msg.getMessage() + ',是否继续操作',
					function(rtn) {
					if(rtn)
						window.location.reload(true);
					else
						window.location.href = __ctx+'/rdp/user/campusCard/list.htm';
					});
			} else {
				DialogUtil.error(msg.getMessage());
			}
		}
	};
})();